package com.annotation.condition;

import com.annotation.bean.Oragin;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class CustomerImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {


    /**
     * @param importingClassMetadata  当前类的注解信息
     * @param registry                BeanDefinition的注册类
     * @param importBeanNameGenerator
     */

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry,
                                        BeanNameGenerator importBeanNameGenerator) {

        String className = importingClassMetadata.getClassName();
        String[] beanDefinitionNames = registry.getBeanDefinitionNames();
        System.out.println(beanDefinitionNames);

        RootBeanDefinition rtb = new RootBeanDefinition(Oragin.class);
        //判断逻辑
        boolean origin = registry.containsBeanDefinition("origin");
        if (!origin) {

            registry.registerBeanDefinition("origin", rtb);
        }
    }
}
